/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            adminRepairInfo: {
                repairs: [],
                states:[],
                roomSubTypes:[],
                total: 0,
                records: 1,
                moreCondition: false,
                conditions: {
                    communityId: '',
                    repairId: '',
                    state: '',
                    repairType:'',
                    repairName:'',
                    tel: '',
                    repairId: '',
                }
            }
        },
        _initMethod: function () {
            vc.emit('communityRepairTree', 'initCommunityRepairTree',{
                callName:'adminRepair'
            });
            $that._listAdminRepairs(DEFAULT_PAGE, DEFAULT_ROWS);


        },
        _initEvent: function () {
            vc.on('adminRepair', 'selectCommunity', function (_param) {
                $that.adminRepairInfo.conditions.communityId = _param.communityId;
                $that.adminRepairInfo.conditions.repairType = '';
                $that.adminRepairInfo.conditions.leaseType = '';
                $that._listAdminRepairs(DEFAULT_PAGE,DEFAULT_ROWS);
            });
            vc.on('adminRepair', 'selectRepairSetting', function (_param) {
                $that.adminRepairInfo.conditions.communityId = _param.communityId;
                $that.adminRepairInfo.conditions.repairType = _param.repairType;
                $that.adminRepairInfo.conditions.state = '';
                $that._listAdminRepairs(DEFAULT_PAGE,DEFAULT_ROWS);

            });
            vc.on('adminRepair', 'selectState', function (_param) {
                $that.adminRepairInfo.conditions.communityId = _param.communityId;
                $that.adminRepairInfo.conditions.repairType = _param.repairType;
                $that.adminRepairInfo.conditions.state = _param.state;
                $that._listAdminRepairs(DEFAULT_PAGE,DEFAULT_ROWS);
            });
            vc.on('adminRepair', 'listAdminRepair', function (_param) {
                $that._listAdminRepairs(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listAdminRepairs(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listAdminRepairs: function (_page, _rows) {
                $that.adminRepairInfo.conditions.page = _page;
                $that.adminRepairInfo.conditions.row = _rows;
                let param = {
                    params: $that.adminRepairInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/ownerRepair.listAdminOwnerRepairs',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.adminRepairInfo.total = _json.total;
                        $that.adminRepairInfo.records = _json.records;
                        $that.adminRepairInfo.repairs = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.adminRepairInfo.records,
                            dataCount: $that.adminRepairInfo.total,
                            currentPage: _page
                        });
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
         
            //查询
            _queryCommunityPublicityMethod: function () {
                $that._listAdminRepairs(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _openRepairDetail: function (_repair) {
                vc.jumpToPage('/#/pages/work/adminRepairDetail?repairId='+_repair.repairId);
            },
            _moreCondition: function () {
                if ($that.adminRepairInfo.moreCondition) {
                    $that.adminRepairInfo.moreCondition = false;
                } else {
                    $that.adminRepairInfo.moreCondition = true;
                }
            },
            _computeTableDivWidth: function () {
                let mainWidth = document.getElementsByTagName('body')[0].clientWidth - document.getElementById('menu-nav').offsetWidth;
                let treeWidth = document.getElementsByClassName('room-floor-unit-tree')[0].offsetWidth;
                mainWidth = mainWidth - 20 - treeWidth - 15 - 20;
                //document.getElementsByClassName('hc-table-div')[0].style.width=mainWidth+'px';
                return mainWidth + 'px';
            },
        }
    });
})(window.vc);